Normalize YAML flow-style docs in post-renderer [SURE-11642]#5180
Open
thardeck wants to merge 1 commit into
Open
Normalize YAML flow-style docs in post-renderer [SURE-11642]#5180thardeck wants to merge 1 commit into
thardeck wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses Helm v4’s kyaml behavior that round-trips toJson output into YAML flow-style with unquoted keys (e.g. {apiVersion: v1, ...}), which later gets misdetected as JSON by apimachinery and can fail during post-render object decoding. The change adds a normalization step in Fleet’s Helm post-renderer to convert those flow-style YAML documents into block-style YAML before decoding.
Changes:
- Add
normalizeFlowStyleDocs+hasFlowStyleCandidateto detect and normalize{...}-prefixed non-JSON YAML documents prior toyaml.ToObjects. - Add a unit test covering the flow-style YAML regression in the post-renderer.
- Add an install/template-level regression test exercising
toJsonrendering through Helm v4.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
internal/helmdeployer/postrender.go |
Adds flow-style YAML normalization pre-pass before decoding rendered manifests. |
internal/helmdeployer/postrender_test.go |
Adds a post-render regression test for flow-style YAML documents. |
internal/helmdeployer/install_test.go |
Adds an end-to-end-ish regression test reproducing the Helm v4 toJson flow-style issue. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e734404 to
d157ee6
Compare
Helm v4's kyaml round-trips rendered manifests through its YAML parser,
converting JSON output from toJson template functions into YAML flow-style
with unquoted keys, e.g. {apiVersion: v1, kind: ConfigMap, ...}.
k8s.io/apimachinery's IsJSONBuffer detects the leading '{' and returns
such documents unchanged assuming they are already valid JSON. Passing
them to json.Unmarshal then fails with 'invalid character' because the
keys are unquoted.
Add normalizeFlowStyleDocs to the post-renderer: before handing the
rendered buffer to yaml.ToObjects, each document starting with '{' is
checked with json.Valid; documents that fail are round-tripped through
sigs.k8s.io/yaml to produce block-style YAML that the existing decode
path handles correctly.
Add hasFlowStyleCandidate as a zero-allocation fast-path: on every render
call, a raw byte scan checks whether any document boundary starts with '{'.
When none does (the common case), normalizeFlowStyleDocs returns the
original slice immediately without any allocation or buffer rebuild.
d157ee6 to
dae1638
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Helm v4's kyaml round-trips rendered manifests through its YAML parser, converting JSON output from
toJsontemplate functions into YAML flow-style with unquoted keys (e.g.{apiVersion: v1, kind: ConfigMap}).k8s.io/apimachinery'sIsJSONBuffertreats the leading{as a signal that the document is already valid JSON and returns it unchanged;json.Unmarshalthen fails withinvalid character 'a' looking for beginning of object key string, causing the bundle deployment to fail in the post-render phase.normalizeFlowStyleDocsinpostrender.go: for each rendered document starting with{that does not passjson.Valid, round-trip it throughsigs.k8s.io/yamlto produce block-style YAML before passing toyaml.ToObjects. Valid JSON documents are not touched.hasFlowStyleCandidateas a zero-allocation fast-path: a raw byte scan checks whether any document boundary starts with{; when none does (the common case), the function returns immediately without allocating or rebuilding the buffer.